using System.Drawing;
using GTA;
using NativeUI;

namespace CustomPeds.Menus;

public class HeadOverlayMenu : Script
{
    public static UIMenu menu = new UIMenu("", TextSetting.ho_Menu, new Point(0, -107));
    private static bool inited;

    public HeadOverlayMenu()
    {
        if (!inited)
        {
            Main.pool.Add(menu);
            menu.OnMenuClose += OnMenuClose;
            menu.OnItemSelect += OnItemSelect;
            inited = true;
        }
    }

    public static void InitHeadOverlayMenu()
    {
        menu.Clear();
        menu.SetBannerType(new UIResRectangle());
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Blemishes));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Beard));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Eyebrows));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Ageing));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Makeup));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Blush));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_SunDamage));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Skin));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Lipstick));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_MolesFreckles));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_ChestHair));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_BodyBlemishes));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_DenseBodyBlemishes));
        for (int i = 0; i <= 12; i++)
        {
            menu.BindMenuToItem(HeadOverlaySubMenu.menu, menu.MenuItems[i]);
        }
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_EyeColor));
        menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_HairColor));
        menu.BindMenuToItem(OtherColorsSubMenu.menu, menu.MenuItems[13]);
        menu.BindMenuToItem(OtherColorsSubMenu.menu, menu.MenuItems[14]);
        menu.RefreshIndex();
        menu.Visible = true;
    }

    private static void OnItemSelect(UIMenu sender, UIMenuItem item, int index)
    {
        if (index >= 0 && index <= 12) HeadOverlaySubMenu.InitHeadOverlaySubMenu(index);
        if (index == 13) OtherColorsSubMenu.InitOtherColorsSubMenu(OtherColorsSubMenu.OtherColors.Eye);
        if (index == 14) OtherColorsSubMenu.InitOtherColorsSubMenu(OtherColorsSubMenu.OtherColors.Hair);
    }

    private static void OnMenuClose(UIMenu sender)
    {
        menu.Visible = false;
        // 不刷新，避免退格链式重绘
    }
}


